using System;
using System.Collections.Generic;
using System.Text;
using Scripting.Forms;
using Scripting;
using Scripts.RCPKit;

namespace UserScripts
{
    /// <summary>
    /// Creates a guild window
    /// </summary>
    public partial class GuildWindow : Form
    {
        public const string FormName = "GuildWindow";
        private List<GuildMember> GuildMembers = new List<GuildMember>();
        private string GuildName = "Siroro's Awesome Guild";
        private string GuildMotd = "RCP kit rocks!";
        //private string 
        public GuildWindow(Actor actor)
        {
            Name = FormName;
            InitializeComponent();
            this.Controls.Remove(guildNameLabel);
            this.Controls.Remove(MOTDText);
            this.Controls.Remove(guildMemberList);
            LoadGuildInfo();
            guildNameLabel.Text = GuildName;
            MOTDText.Text = GuildMotd.ToString();

            foreach (GuildMember Member in GuildMembers)
            {
                if(Member.ActorLocation == "Offline")
                    guildMemberList.Items.AddRange(new string[] { @"\c=#FF0000" + Member.ActorName + " | " + Member.ActorLocation + " | " + Member.ActorGuildrole.ToString() });
                else
                    guildMemberList.Items.AddRange(new string[] { @"\c=#00FF00" + Member.ActorName + " | " + Member.ActorLocation + " | " + Member.ActorGuildrole.ToString() });
            }
            this.Controls.Add(guildNameLabel);
            this.Controls.Add(guildMemberList);
            this.Controls.Add(MOTDText);
        }

        public void LoadGuildInfo()
        {
            if (DatabaseSettings.DatabaseProvider == DatabaseType.SQLite)
            {
                //just for testings.
                for (int i =0; i < 10;i++)
                {
                    GuildMembers.Add(new GuildMember("Siroro" + i.ToString(), i > 0 ? "Offline" : "DefaultZone", true, GuildRole.Member));
                }
            }
            else if (DatabaseSettings.DatabaseProvider == DatabaseType.MySQL)
            {

            }
            else
            {
                RCScript.Log("You are using an unsupported database type");
            }
        }
        

        // Player clicked the corner X
        private void form_Closed(object sender, FormEventArgs e)
        {
            // CloseDialog calls Closing(false) which we use
            // to dispatch the final messages.
            Actor.CloseDialog(this);
        }

        private void Closed(object sender, FormEventArgs e)
        {
            // CloseDialog calls Closing(false) which we use
            // to dispatch the final messages.
            Actor.CloseDialog(this);
        }

        // Player clicked 'Cancel'
        private void CancelButton_Click(object sender, FormEventArgs e)
        {
            // Its the same as closing
            form_Closed(sender, e);
        }
        
        // Called when form is closing
        public override void Closing(bool forZoning)
        {
            if (forZoning)
                Actor.CloseDialog(this);
        }
        
    }
}
